
# Copyright 2009 David Lee Miller
#
# This file is part of POSSM (Python Open Source Scanning Microscopy).
#
# POSSM is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# POSSM is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License         
# along with POSSM.  If not, see <http://www.gnu.org/licenses/>.
#                                                                           
# # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #

import os

STM_PREFIX	= 'b'
CONTROLLERS	= {'stmb':'phys43229','stmc':'not built','localhost':'127.0.1.1'}
VERSION		= '0.99' #On new verison releases, update here

#---- Storage Options ----

BASE_DIRECTORY	= os.environ.get('HOME')
DATA_DIRECTORY	= '/rawdata'
EXTENSION	= '.nc'
SAVE_DIGITS	= 7
DEFAULT_SIZE	= (1650, 1000) # Adjust for your screen resolution
MAX_FPS		= 10 # Max frames per second that the display will update

#---- Default Save Options ----

SAVE_IMAGE	= 'y' # Choose y for the scan to save by default
SAVE_IMAGEWIV	= 'y' # Choose y for the scan to save by default
SAVE_MULTIBIAS	= 'y' # n not to save by default and a for the program
SAVE_CONTINUOUS	= 'f' # to ask before saving. f is fast save which saves
SAVE_SINGLEIV	= 'a' # without asking for a comment.
SAVE_SINGLEIZ	= 'a'
SAVE_SINGLEZV	= 'a'

#---- Scan Runtime ----

BIAS_RESTRICT	= 0.1 # Sets the minimum value of the bias

#---- Conversion Factors ----

VOLTS_PER_ADU	= 20./(2**16) #20 volt range / 2**number of bits
ANG_PER_VOLT_X	= 2137.2 #These next 3 values are piezo constants
ANG_PER_VOLT_Y	= 2137.2
ANG_PER_VOLT_Z	= 21.824
NAMP_PER_VOLT	= 1	#Number needs a fixin'
Z_MULTIPLIER	= -1	#A direct multiplier to the data. Used on room
			#temperature system to invert the data since higher z
			#topology corresponds to a larger negative voltage

#---- Rates ----

#The following are ramp rates
XOFF_RATE	= 2e3 # Ramp Rates in Hz. The physical ramp rate is given
YOFF_RATE	= 2e3 # by XOFF_RATE*VOLTS_PER_ADU*ANG_PER_VOLT_X*GAIN = physical rate
ZOFF_RATE	= 2e3 # in angstroms/s
ZPLANE_RATE	= 2e3
OFFSET_STEP	= 3   # The step size for the offsets
TIP_RATE	= 3e3
TIP_STEP	= 10
XSTART_RATE	= 1e4
YSTART_RATE	= 1e4
XRETURN_RATE	= 1e4
YRETURN_RATE	= 1e4
XMAX_RATE	= 5e4
YMAX_RATE	= 5e4

#---- Ports ----

#Controller ports (5 required)
PORT_CONTROLLER	= (22222,22223,22224,22225,22226) #Must be the same at controller at client


#---- Hardware Settings ----

# Device paths
DEV0_NUMBER = 1 # These are the numbers in the path to your comedi device
DEV1_NUMBER = 0 # i.e.  /dev/comedi#

#The following are analog output
XCHAN		= (0,0,0) #Moves the x-scan (device#,channel,range)
YCHAN		= (0,1,0) #Moves the y-scan (device#,channel,range)
TIP_VOLTS	= (1,0,0) #Channel which sets the tip/sample bias (device#,channel,range)
XOFF_CHAN	= (1,1,0) #Summed with 'XCHAN'to set the constant x offset (device#, channel,range) 
YOFF_CHAN	= (1,2,0) # ""     ""  'YCHAN'             ""     y offset    ""        ""     ""
ZOFF_CHAN	= (1,3,0) # ""     ""  'ZCHAN'             ""     z offset    ""        ""     ""
ZPLANE_CHAN	= (1,4,0) # ""	   ""  'ZPLANE'            ""	  z plane     ""        ""     ""

#The following are analog input.
TIP_CURRENT	= (0,1,0) #The device/channel where the tip current is read (device#,channel,range)
ZPOS		= (0,0,0) # ""       ""         ""      z-position      ""      ""      ""     ""
GAIN_ZPLANE	= 1./10     #Must be a float!
SCAN_GAIN	= 1./10

#---- Parallel Port ----

## PNF 15-JUL-2008: Reversed AXIS1 and AXIS2 entries b/c controller changed: AXIS1 now controls "Axis 2" on hardware.
AXIS1_DIRECTION	= 3 #These are the bit arrangements for the inchworm.
AXIS2_DIRECTION	= 1 #  Clock is what moves the inchworm and direction
AXIS1_CLOCK	= 2 #  defines which way it goes - 1 is forward.	
AXIS2_CLOCK	= 0
AXIS1_HALT	= 5
AXIS2_HALT	= 4

#---- Coarse Move ----

CM_FORWARD = '1'	# Codes are a alphanumeric string of length 1. Unlikely that these need to be
CM_BACK = '2'		# changed; however if new coarse motion directions are added, would need to add
CM_LEFT = '3'		# codes.
CM_RIGHT = '4'
CM_UP = '5'
CM_DOWN = '6'
CM_CW = '7'
CM_CCW = '8'

#---- Inchworm Parameters ----
RETRACT		= 1 #Retract bit number
HOLD		= 0 #Hold    ""   ""

FORWARD		= 1 #Forward bit low/high
REVERSE		= 0 #Reverse ""     ""

CENTER_DIFF0	= 7 #Beyond this tip extension voltage it is safe to take
CENTER_DIFF1	= 3 #  the corresponding number of steps (CD_STEP#)
CENTER_DIFF2	= 2
CENTER_DIFF3	= 1
CENTER_DIFF4	= 0.25
CD_STEP0	= 200 #The number of safe steps to take when tip voltage reads
CD_STEP1	= 75  #  CENTER_DIFF# or above
CD_STEP2	= 30
CD_STEP3	= 10
CD_STEP4	= 2

CENTER_RETRACT	= -9	#Voltage to retract to while tip is centering
CENTER_SWEEP	= 9.5	#Voltage to sweep to while tip is centering

RETRACT_DELAY	= 0.005	#Delay time between successive reads (s)
SWEEP_DELAY	= 0.005 #  ""   ""    ""        ""      ""
RETRACT_NREADS	= 100	#Number of reads to take on the z-position during retract
SWEEP_NREADS	= 100	#  ""         ""            ""          ""        sweep

INCHES		= 1000	#Number of micro steps in inchworm clamp cycle

slowrate	= 40000	#for inchworm steps (period = 1/slowrate)
fastrate	= 125000
INCH_DELAY	= 0.010	#delay between inchworm bigsteps (s)

Z_MIN_VOLTS	= -10
Z_MAX_VOLTS	= 10
Z_MAX_ERR	= 9.5	#The error that the tip sweeps to before deciding there is no tunneling
SWEEP_TIMEOUT	= 7	#Wait time before sweep decides it has found the sample
CENTER_TIMEOUT	= 10	# ""   ""    ""   center  ""         ""            ""
TUNNEL_TIMEOUT	= 15	# ""   ""    ""   tunnel  ""         ""            ""
WITHDRAW_STEPS	= 5	#The number of bigsteps to withdraw

#---- Scan Rate Calibration ----

READ_TIME	= 20.e-6


#---- Display Settings ----
TITLE_SIZE	= 16 #Font sizes in relation to the aspect size.
AXES_SIZE	= 12
ASPECT_W	= 5  #Aspect ratio of the figures for matplot
ASPECT_H	= 4
ASPECT_SIZE	= 80
DEFAULT_COLOR	= ('#999999','#999900','#000000','#F00000','#FF0000','#FFF000','#FFFF00',\
		'#900000','#990000','#999000','#999990','#000000','#FFFFF0','#000000','#000000',\
		'#000000','#000000','#000000','#000000','#000000') # Default colors used in order
POINT_TYPE	= '-' # The dash will produce a line plot. Changing to '.' will do points.
LINE_WEIGHT	= 2   # The weight of the lines for spectroscopy data
DISPLAY_DIR	= 0   # 0 displays reverse data, 1 displays the forward direction
N_ALLOWED_TABS	= 6   # Maximum number of tabs to have on the scan display
DEFAULT_CMAP	= 'gray'
DEFAULT_INTERP	= 'bilinear'
IM_ASPECT_W	= 7
IM_ASPECT_H	= 7
IM_ASPECT_SIZE	= 75

BIAS_LABEL	= 'Sample Bias'
CURRENT_LABEL	= 'Tunneling Current'
HEIGHT_LABEL	= 'Z Height'

#--- Client Hotkeys ---
SEND_GO		= 'f4'  #every key is listed in lower case. options are f1-12 keys, esc,
SEND_ABORT	= 'esc' # insert,scroll,home,end,up,down,left,right,pgup,pgdn,pause,del, tab
CONNECT		= 'f2'
DISCONNECT	= 'f12'
HELP_SELECTED	= 'f1'
SCAN_SELECTED	= 'f3'
BLIT_OLDSCAN	= 'f5'

#--- wxGrid Colors ---
GRID_NORMAL	= '#FFFFCC'
GRID_READONLY	= '#CCFFFF'
GRID_INFO	= '#CCFF99'

#--- Editor Settings ---
PDF_VIEWER	= 'okular' #make sure this matches an installed program and supports the format
				# <program> filename.pdf   from the command line
LATEX2PDF	= 'pdflatex'
BIBTEX		= 'bibtex'
LABBOOKPATH	= 'labbook/'
IMAGEPATH	= LABBOOKPATH+'images/'
ICONPATH	= 'icons/'
